package com.misty.admin.controller.adminController;


import com.misty.admin.service.TagService;
import com.misty.common.bean.Result;
import com.misty.dao.domain.Tag;
import com.misty.dao.mapper.TagMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author cthulhu
 * @since 2022-11-21
 */
@RestController
@RequestMapping("/tag")
@PreAuthorize("hasAuthority('tag')")
public class TagController {

    @Autowired
    private TagService tagService;
    @Resource
    private TagMapper tagMapper;

    @PostMapping("/save")
    public Result<?> save(@RequestBody Tag tag) {
        return tagService.saveTag(tag);
    }

    @PutMapping("/update")
    public Result<?> update(@RequestBody Tag tag) {
        return tagService.updateTag(tag);
    }

    @DeleteMapping("/delete")
    public Result<?> delete(@RequestParam(name = "id") Integer tagId) {
        return tagService.deleteTag(tagId);
    }

    @GetMapping()
    public Result<?> Page(
            @RequestParam(defaultValue = "1") Integer pageNum,
            @RequestParam(defaultValue = "10") Integer pageSize,
            @RequestParam(defaultValue = "") String search
    ) {
        return tagService.Page(pageNum,pageSize,search);
    }
}

